{
 "cells": [
  {
   "cell_type": "raw",
   "id": "55e7acccf0512da9",
   "metadata": {},
   "source": [
    "from typing_extensions import TypedDict\n",
    "\n",
    "class State(TypedDict):\n",
    "    graph_state: str"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5202e4d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "def node_1(state):\n",
    "    print(\"---Node 1---\")\n",
    "    return {\"graph_state\": state['graph_state'] +\"我很\"}\n",
    "\n",
    "def node_2(state):\n",
    "    print(\"---Node 2---\")\n",
    "    return {\"graph_state\": state['graph_state'] +\"高兴!\"}\n",
    "\n",
    "def node_3(state):\n",
    "    print(\"---Node 3---\")\n",
    "    return {\"graph_state\": state['graph_state'] +\"悲伤!\"}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "379f1682",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "from typing import Literal\n",
    "\n",
    "def decide_mood(state) -> Literal[\"node_2\", \"node_3\"]:\n",
    "    \n",
    "    # 通常，我们会使用状态来决定下一个要访问的节点\n",
    "    user_input = state['graph_state'] \n",
    "    \n",
    "    # 在这里，我们在节点 2、3 之间进行 50/50 的分割\n",
    "    if random.random() < 0.5:\n",
    "\n",
    "        # 50% 的时间，我们返回节点 2\n",
    "        return \"node_2\"\n",
    "    \n",
    "    # 50% 的时间，我们返回节点 3\n",
    "    return \"node_3\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5470cfc3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
